
package backupUtility;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
/**
 * The FileListGetter class is responsible for getting the list of files
 * modified or created within the past hour and a half
 * @author Changcoco Kevin Paolo
 * @author Mamis Dominique Bernard
 * @author Palasi Jandy
 * @author Rafael Ian Paolo 
 */
public class FileListGetter {
    
    private String root;
    private long currentTime;
    private long previousTime;
    private int timeChosen;
    private ArrayList<File> arrayListofFiles = new ArrayList<File>();
 /**
 * This class sets the path for the root, where the search will start
 * and then executes the search method.
 */   
    public FileListGetter(){
        this.timeChosen = timeChosen;
        this.currentTime = getCurrentTime();
        this.previousTime = getPreviousTime();
        root = "C:/Users/";
        File file = new File(root);
        search(file);
        //root = "D:/";
        //File secondFile = new File(root);
        //search(secondFile);
    }
    /**
     * Searches the files that are modified based on the time the user inputs
     * @param root the file directory to be searched
     */    
    public void search(File root) {
        //System.out.println(root);
        File[] listOfFiles = root.listFiles();
        if(listOfFiles == null) return;  
        for (File file : listOfFiles) {         
                String path = file.getPath().replace('\\', '/');
                 //System.out.println(path);
                if(file.isFile()&& 
                   file.lastModified() > previousTime && 
                   file.lastModified() < currentTime &&
                   !file.isHidden()){
               // System.out.println(path);
                getArrayListofFiles().add(file);
                 //System.out.println(file.getName()+ " "+file.lastModified());
                }
                 if (file.isDirectory()) {
                // System.out.println(path);
                 search(file);
                 }
                }
            }
    /**
     * Gets the current time of the system and stores it in a variable
     * @return currentTime  
     */
    public long getCurrentTime(){
        long currentTime = System.currentTimeMillis();
        return currentTime;
    }
    /**
     * Gets the current time of the system and subtracts one hour and a half,
     * and then store it in a variable called previousTime. 
     * @return previousTime 
     */
    public long getPreviousTime(){
        long previousTime = currentTime - (1000 * 60 * 90);
        return  previousTime;
    }
    /**
     * Returns an array of files that will be displayed in the screen when the
     * FileListUI is invoked. 
     * @return arrayListofFiles 
     */
    public ArrayList<File> getArrayListofFiles() {
        return arrayListofFiles;
    }
        
    }